package com.shengyin.ec.service.delivery;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shengyin.ec.model.dao.delievery.DelieveryDao;
import com.shengyin.ec.model.entity.Delivery;
import com.shengyin.ec.model.entity.GoodsType;

@Service(value = "delieveryService")
public class DelieveryServiceImpl implements DelieveryService {

	@Autowired
	DelieveryDao delieveryDao;

	public List<Delivery> getDelieveryList() {
		List<Delivery> DelieveryList = delieveryDao.loadAll();
		return DelieveryList;
	}

	@Override
	public void createDelievery(Delivery delievery) {
		System.out.println(delievery.getDelieveryName());
		delieveryDao.save(delievery);
	}

	@Override
	public void removeDelieveryById(long id) {
		delieveryDao.deleteByKey(id);
	}

	@Override
	public void modifyDelievery(Delivery delivery) {

		
		try {
			Delivery delivery1 = delieveryDao.get(delivery.getId());
			BeanUtils.copyProperties(delivery1, delivery);
			delieveryDao.update(delivery1);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
	}

	@Override
	public Delivery getDeliveryById(long id) {
		return delieveryDao.get(id);
	}
}
